import os
import os.path
import tempfile
from unittest import TestCase, mock
from mock_demo.module2 import rm
import mock_demo


class RmTestCase(TestCase):
    def setUp(self):
        self.tmpfilepath = os.path.join(tempfile.gettempdir(), "tmp-testfile")
        with open(self.tmpfilepath, "w") as f:
            f.write("Delete me!")
        
    def test_rm(self):
        self.assertTrue(os.path.isfile(self.tmpfilepath), "file %s not exists" % self.tmpfilepath)
        rm(self.tmpfilepath)
        self.assertFalse(os.path.isfile(self.tmpfilepath), "Failed to remove the file.")


def mock_rm(filename):
    print('Remove %s in mock_rm' % filename)


class RmMockTest(TestCase):
    @mock.patch('mock_demo.module2.MyOS.remove')
    def test_rm(self, mock_remove):
        mock_remove.side_effect = mock_rm
        rm('any file')
